<div class="view catalogo">
    
        <?php
        $category = Category::model()->findByAttributes(array('tag'=>$data->collection));
        $subcategory = Subcategory::model()->findByAttributes(array('tag'=>$data->collection_sub));
        $quoteDollar = Config::model()->findByAttributes(array('tag'=>'dollar_quote'));
        $quoteThaiBaht = Config::model()->findByAttributes(array('tag'=>'thai_baht_quote_to_usd'));
        if($category == null OR $category->name == 'NO TIENE TRADUCCION'){//TODO ver cuando agregue las cat sin nombre traducido, (encuentra obj pero no tiene nada)
            $nameCategory = $data->collection;
        } else {
            $nameCategory = $category->name;
        }
        if($subcategory == null OR $subcategory->name == 'NO TIENE TRADUCCION'){
            $nameSubcategory = $data->collection_sub;
        } else {
            $nameSubcategory = $subcategory->name;
        }
        $nameItem = "<b>".CHtml::encode($nameSubcategory)."</b> - ".CHtml::encode($nameCategory);
        $priceSet = PriceProduct::model()->findByAttributes(array('id_ref'=>$data->ref));
        $priceWholesale = $priceSet->wholesale_price;
        $priceRetail = $priceSet->retail_price;
        
        if(Yii::app()->user->name == 'admin') {
            $priceARG = round(($data->price_thb*$quoteThaiBaht->value)*$quoteDollar->value, 2);
            $priceUSD = round($data->price_thb*$quoteThaiBaht->value, 2);
        } else if(Yii::app()->user->name == 'mayorista'){
            $profitMargin = Config::model()->findByAttributes(array('tag'=>'wholesale_price'));
            if(empty($priceWholesale)){
                $priceMay = round((($data->price_thb + ($data->price_thb * $profitMargin->value / 100))*$quoteThaiBaht->value)*$quoteDollar->value);
            }else{
                $priceMay = $priceWholesale;
            } 
        } else if(Yii::app()->user->name == 'cliente'){
            $profitMargin = Config::model()->findByAttributes(array('tag'=>'retail_price'));
            if(empty($priceRetail)){
                $priceCli = round((($data->price_thb + ($data->price_thb * $profitMargin->value / 100))*$quoteThaiBaht->value)*$quoteDollar->value);
            } else {
                $priceCli = $priceRetail;
            } 
        } ?>

        <?php if(Yii::app()->user->isGuest){ 
        $img = 'http://link.ecomsite.net/m1.php?ref='.$data->ref;
        $this->widget('ext.lyiightbox.LyiightBox2', array(
            'thumbnail' => $img,
            'image' => $img,
            'title' => CHtml::encode($nameSubcategory)." - ".CHtml::encode($nameCategory),
            'visible' => true,
            'group' => 'myOwnGallery'
        )); } ?>
    
        <?php if(Yii::app()->user->name == 'admin'){ 
        $img = 'http://link.ecomsite.net/m1.php?ref='.$data->ref;
        $this->widget('ext.lyiightbox.LyiightBox2', array(
            'thumbnail' => $img,
            'image' => $img,
            'title' => CHtml::encode($nameSubcategory)." - ".CHtml::encode($nameCategory)."<h3>".CHtml::encode($data->ref)."</h3><span class='price'>ARS: $".CHtml::encode($priceARG)." - USD: $".CHtml::encode($priceUSD)."</span>",
            'visible' => true,
            'group' => 'myOwnGallery'
        )); } ?>
    
        <?php if(Yii::app()->user->name == 'mayorista'){//mayorista
        $img = 'http://link.ecomsite.net/m1.php?ref='.$data->ref;
        $this->widget('ext.lyiightbox.LyiightBox2', array(
            'thumbnail' => $img,
            'image' => $img,
            'title' => CHtml::encode($nameSubcategory)." - ".CHtml::encode($nameCategory)."<h3>".CHtml::encode($data->ref)."</h3><span class='price'>Precio (ARS): $".CHtml::encode($priceMay),
            'visible' => true,
            'group' => 'myOwnGallery'
        )); } ?>
    
        <?php if(Yii::app()->user->name == 'cliente'){//cliente
        $img = 'http://link.ecomsite.net/m1.php?ref='.$data->ref;
        $this->widget('ext.lyiightbox.LyiightBox2', array(
            'thumbnail' => $img,
            'image' => $img,
            'title' => CHtml::encode($nameSubcategory)." - ".CHtml::encode($nameCategory)."<h3>".CHtml::encode($data->ref)."</h3><span class='price'>Precio (ARS): $".CHtml::encode($priceCli),
            'visible' => true,
            'group' => 'myOwnGallery'
        )); } ?>
    
	<span class="titleItem"><?php echo CHtml::link($nameItem, array('view', 'id'=>$data->ref)); ?></span><br />
        
        <b><?php echo CHtml::encode($data->getAttributeLabel('ref')); ?>:</b>
	<b><?php echo CHtml::encode($data->ref); ?></b>
	<br />
        
        <?php if(!empty($data->p_size)) { ?>
        <b><?php echo CHtml::encode($data->getAttributeLabel('p_size')); ?>:</b>
	<?php echo CHtml::encode($data->p_size.' g');?>
	<br />
        <?php } ?>
        
        <?php if(!empty($data->length)) { ?>
        <b><?php echo CHtml::encode($data->getAttributeLabel('length')); ?>:</b>
	<?php echo CHtml::encode($data->length.' '.$data->length_unit);?>
	<br />
        <?php } ?>
        
        <?php if(!empty($data->stone)) { ?>
        <b><?php echo CHtml::encode($data->getAttributeLabel('stone')); ?>:</b>
	<?php echo CHtml::encode($data->stone);?>
	<br />
        <?php } ?>

        <?php if(Yii::app()->user->name == 'admin'){//admin?>
            <b>Costo (ARS):</b>
            <span class="price">$<?php echo CHtml::encode($priceARG); ?></span><br />
            <b>Costo (USD):</b>
            <span class="price">$<?php echo CHtml::encode($priceUSD); ?></span><br />
        <?php } ?>

        <?php if(Yii::app()->user->name == 'mayorista') {?>
            <b>Precio (ARS):</b>
            <span class="price">$<?php echo CHtml::encode(round($priceMay)); ?></span><br />
        <?php } ?>
            
        <?php if(Yii::app()->user->name == 'cliente') {?>
            <b>Precio (ARS):</b>
            <span class="price">$<?php echo CHtml::encode($priceCli); ?></span><br />
        <?php } ?>
</div>